import socket
from concurrent.futures import ThreadPoolExecutor

def main():
    ss = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    ss.connect(("127.0.0.1",18888))
    ex = ThreadPoolExecutor(3)
    ex.submit(recv,ss)
    ex.submit(say, ss)

def recv(ss):
    while True:
        data = ss.recv(1024).decode('utf8')
        if len(data) == 0:
            break
        print(data)

def say(ss):
    while True:
        data = input('输入:')
        ss.send(data.encode('utf8'))
        if data == 'BAY':
            break

if __name__ == '__main__':
    main()